package com.wskj.insuranceweb.reporter.controller;

import com.wskj.insuranceweb.reporter.pojo.Accident;
import com.wskj.insuranceweb.reporter.pojo.Employee;
import com.wskj.insuranceweb.reporter.pojo.Users;
import com.wskj.insuranceweb.reporter.service.EmployeeService;
import com.wskj.insuranceweb.reporter.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Controller
@RequestMapping("/employee")
public class EmployeeController {
    @Autowired
    private EmployeeService service;
    @Autowired
    private UserService userService;


    @RequestMapping("/login")
    public String login(){
            return "login";
    }

    @RequestMapping("/login1")
    public String login(Employee employee, HttpServletRequest request){
        System.out.println(employee);
        Employee e = service.findEmployeeByUserName(employee);

        if(e==null){
            return "redirect:/login";
        }else{
            List<Users> list = userService.findAll();
            List<Accident> list1 = userService.findAccident();
            request.getServletContext().setAttribute("accidentList",list1);
            request.getServletContext().setAttribute("userList",list);
            request.getSession().setAttribute("employee",e);
            return "index";
        }
    }
}
